package com.faithbj.device.service.impl;

import javax.annotation.Resource;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.faithbj.device.dao.StockItemDao;
import com.faithbj.device.model.configuration.Pager;
import com.faithbj.device.model.entity.Stock;
import com.faithbj.device.model.entity.StockItem;
import com.faithbj.device.service.StockItemService;

@Service("stockItemService")
@Transactional
public class StockItemServiceImpl implements StockItemService {
	
	@Resource
	private StockItemDao stockItemDao;

	@Override
	public Pager findByPager(Pager pager) {
		return stockItemDao.findByPager(pager);
	}

	@Override
	public StockItem load(String id) {
		return stockItemDao.load(id);
	}

	@Override
	public StockItem get(String id) {
		return stockItemDao.get(id);
	}

	@Override
	public void update(StockItem persistent) {
		stockItemDao.update(persistent);
	}

	@Override
	public void save(StockItem con) {
		stockItemDao.save(con);
	}

	@Override
	public void delete(String id) {
		stockItemDao.delete(id);
	}

	@Override
	public Pager findByPager(Pager pager, Stock stock) {
		DetachedCriteria criteria = DetachedCriteria.forClass(StockItem.class);
		criteria.add(Restrictions.eq("stock", stock));
		return stockItemDao.findByPager(pager, criteria);
	}

}
